import java.net.InetAddress;
import java.net.UnknownHostException;

import jpcap.packet.ARPPacket;

public class ARPThread extends Thread{
	
	ARPThread(){}
	
	@Override
    public void run () {
		while(ARPFace.n<=254 && ARPFace.flag){
			System.out.println(ARPFace.netIP+ARPFace.n);
			ARPFace.textArea.append(ARPFace.netIP+ARPFace.n+"\n");
			ARPPacket arpP;
			try {
				arpP = ARPSearch.getTargetMAC(InetAddress.getByName(ARPFace.netIP+ARPFace.n));
				if(arpP==null){			}
				else{
					ARPFace.textArea.append("硬件类型：" 	+ arpP.hardtype+"\n");
					ARPFace.textArea.append("操作类型：" 	+ arpP.operation+"\n");
					ARPFace.textArea.append("源 MAC 地址："	+ arpP.getSenderHardwareAddress()+"\n");
					ARPFace.textArea.append("源 IP 地址 ：" 	+ arpP.getSenderProtocolAddress()+"\n");
					ARPFace.textArea.append("目标 MAC 地址    "	+ arpP.getTargetHardwareAddress()+"\n");
					ARPFace.textArea.append("目标 IP 地址     " + arpP.getTargetProtocolAddress()+"\n");
					ARPFace.textArea.append("===================================\n");
					System.out.println("硬件类型：" 		+ arpP.hardtype);
					System.out.println("操作类型：" 		+ arpP.operation);
					System.out.println("源 MAC 地址：" 	+ arpP.getSenderHardwareAddress());
					System.out.println("源 IP 地址 ：" 	+ arpP.getSenderProtocolAddress());
					System.out.println("目标 MAC 地址    " 	+ arpP.getTargetHardwareAddress());
					System.out.println("目标 IP 地址     " 	+ arpP.getTargetProtocolAddress());
					System.out.println("===================================");
					}
				ARPFace.n++;
				if (ARPFace.n > 254)	ARPFace.n =1;
				} catch (UnknownHostException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}
	}
}